package com.hsd.service.impl;

import com.hsd.constant.ErrorConstant;
import com.hsd.service.RadixService;
import org.springframework.stereotype.Service;

/**
 * @ Author：YangYu
 * @ Package：com.hsd.service.impl
 * @ Project：hsd_calculator
 * @ Description:
 * @ Date：2025/4/13  16:45
 */
@Service
public class RadixServiceImpl implements RadixService {


    @Override
    public int toten(String binary) {
        return Integer.parseInt(binary, 2);
    }


    @Override
    public String totwo(String decimal) {
        //将十进制转化为二进制
        try {
            int num = Integer.parseInt(decimal);
            return Integer.toBinaryString(num);
        } catch (NumberFormatException e) {
            return ErrorConstant.PARAM_ERROR;
        }
    }
}
